package com.kgc.springboot_shiro.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kgc.springboot_shiro.entity.User;
import com.kgc.springboot_shiro.service.UserService;
import com.kgc.springboot_shiro.mapper.UserMapper;
import com.kgc.springboot_shiro.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author main
* @description 针对表【t_user】的数据库操作Service实现
* @createDate 2023-01-10 14:54:54
*/
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public void redister(User user) {
        String salt = SaltUtils.getSalt(8);

        System.out.println("salt = " + salt);
        user.setSalt(salt);
        Md5Hash md5Hash = new Md5Hash(user.getPassword(),salt,1024);
        System.out.println("md5Hash = " + md5Hash.toHex());
        user.setPassword(md5Hash.toHex());
        userMapper.insert(user);
    }
}




